
<?php include './application/views/top.php'; ?>

<script src="/resource/js/circle-progress.js"></script>

<div class="clear h50"></div>
<div class="layout registry">
	<div class="wrap">
    	<div class="left">
        <form id="reg_form">
        <input type="hidden" name="act" value="reg" />
        <input type="hidden" value="1" name="agr" checked="checked" >
			<dl>
            	<dt><i>*</i><H3>用&nbsp;&nbsp;户&nbsp;&nbsp;名</H3></dt>
                <dd><input id="username" class="input-login" type="text" onblur="setMsg(this,'请输入用户名');" onfocus="clearText(this,'请输入用户名');" name="username" value="请输入用户名"></dd>
			</dl>
			<dl>
            	<dt><i>*</i><H3>手机号码</H3></dt>
                <dd><input id="phone" class="input-login" type="text" onblur="setMsg(this,'请输入手机号码');" onfocus="clearText(this,'请输入手机号码');" name="phone" value="请输入手机号码"></dd>
			</dl>  
			<dl>
            	<dt><i>*</i><H3>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</H3></dt>
                <dd>
				<input class="input-login" id="pwdtxt" type="text" value="请输入密码" onfocus="showPwd();">
				<input class="input-login" id="password" type="password" name="password" style="display:none" value="" onblur="showPwdVal();"  >
                </dd>
			</dl>
			<dl>
            	<dt><i>*</i><H3>重复密码</H3></dt>
                <dd>
				<input class="input-login" id="pwdtxt2" type="text" value="请确认密码" onfocus="showPwd2();">
				<input class="input-login" id="password2" type="password" name="password2" style="display:none" value="" onblur="showPwdVal2();">
                </dd>
			</dl>
			<dl>
            	<dt><i>*</i><H3>验&nbsp;&nbsp;证&nbsp;&nbsp;码</H3></dt>
                <dd>
				<input class="input-two" id="verify_code"  type="text"  name="verify_code" value="" maxlength="6" onblur="setMsg(this,'请输入验证码');" onfocus="clearText(this,'请输入验证码');" value="请输入验证码">
                <span><a href="javascript:;" onclick="phoneSubmit();" class="login_yzm" id="phone_code"> 获取验证码</a></span>
                </dd>
			</dl>
			<p class="send">
            	<a href="javascript:void();" onclick="reg_submit();" >同意协议并注册</a>
            </p>
            <p>
            	<a href="/site/danyue/shiyong.html" target="_blank" style="color:red; margin-left:128px; line-height:42px;">&lt;&lt;阅读服务条款协议&gt;&gt;</a>
            </p>
        </form>
        </div>
        <div class="right">
        <img src="/resource/images/plfreg.png">
        </div>
    </div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script type="text/javascript">

    function clearText(e,msg){
        if(e.value == msg){
            e.value = '';
        }
    }

    function setMsg(e,msg){
        if(e.value == ''){
            e.value = msg;
        }
    }

    function showPwd(){
        $('#pwdtxt').css('display','none');
        $('#password').css('display','');
        $('#password').focus();
    }
    function showPwdVal(){
        if($('#password').val()==''){
            $('#password').css('display','none');
            $('#pwdtxt').css('display','');
        }
    }
    function showPwd2(){
        $('#pwdtxt2').css('display','none');
        $('#password2').css('display','');
        $('#password2').focus();
    }
    function showPwdVal2(){
        if($('#password2').val()==''){
            $('#password2').css('display','none');
            $('#pwdtxt2').css('display','');
        }
    }

    function reg_submit(){
        var options = {
            url : '/reg',
            //clearForm :true,
            //resetForm :true,
            beforeSubmit:  checkForm,
            dataType: "json",
            type:"post",
            success : function(ret) {
                console.log(ret);
                if(ret.msg==''){
                    $('#dialog').dialog({
                        modal:true, //蒙层（弹出会影响页面大小）
                        title:'系统提示',
                        buttons:{"确定":function(){$(this).dialog("close");}},
                        //ui-dialog-titlebar-close
                        close: function() {
                            //location=ret.data.url;
                            if(ret.data.url==''){
                                window.location.reload();
                            }else{
                                window.location=ret.data.url;
                            }
                        }
                    });
                    $("#msg").html("注册成功!同时，为了您账户安全，请您完成邮箱与实名认证。"+ret.sycDz);
                }else{
                    $('#dialog').dialog({
                        modal:true, //蒙层（弹出会影响页面大小）
                        title:'系统提示',
                        buttons:{"确定":function(){$(this).dialog("close");}}
                        //ui-dialog-titlebar-close
                    });
                    $("#msg").html(ret.msg);
                }
            }
        };
        $("#reg_form").ajaxSubmit(options);
        return false;
    }


    function checkForm(){
        //return true;
        var err = '';
        var emailV = $("#email").val();
        var username = $("#username").val();
        var password = $("#password").val();
        var verify_code = $("#verify_code").val();
		var phone = $('#phone').val();
        //用户名正则
        var nameReg = /^[\w]{6,16}$/;
        //邮箱正则
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        //密码正则
        var psd= /^[\w]{6,16}$/;
        //密码全数字
        var psdnum =/^[0-9]{6,16}$/;
		//密码所有字符一样
		//手机正则验证
		var phoneReg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(147))+\d{8})$/;
		if(password != '') {
			var pwdVal = false;
			var oneVal = password[0];
			var psdLen = password.length;
			for(var i=1;i<psdLen;++i) {
				if(oneVal != password[i]) {
					var pwdVal = true;
					i = psdLen;
				}
			}
		}
//        if(emailV == '' || emailV == '请输入邮箱'){
//            err = '请输入邮箱';
//        }else if(! reg.test(emailV)){
//        	err = '请输入有效的E_mail！';
//    	}else if(username =='' || username == '请输入用户名'){
//            err = '请输入用户名';
//        }else if(! nameReg.test(username)){
//            err = '用户名格式不对！【6-16位字符】';}else 
        if(password == '' || password == '请设置密码'){
            err = '请输入密码';
        }else if(! psd.test(password)){
			err = '密码格式不对！<br/>【6~16位、不能为纯数字、同一字符】';
        }else if(psdnum.test(password)){
			err = '密码不能全为数字';
        }else if(!pwdVal) {
			err = '密码字符不能全部一样';
        }else if(password != $('#password2').val()){
            err = '两次密码不一致';
        }else if(phone == '' || phone == '请输入手机号码'){
            err = '请输入手机号码';
        }else if(!phoneReg.test(phone)) {
			err = '请输入有效手机号';
        }else if(verify_code == ''){
			err = '请输入验证码';
        } 
        
        if(err==''){
            return true;
        }else{
            $('#dialog').dialog({
                modal:true, //蒙层（弹出会影响页面大小）
                title:'系统提示',
                buttons:{"确定":function(){$(this).dialog("close");}},
                close: function() {
                    //	$("#reg_form").resetForm();
                }
            });
            $("#msg").html(err);
            return false;
        }
    }

    function get_length(s){
        var l = 0;
        var a = s.split("");
        for (var i=0;i<a.length;i++) {
            if (a[i].charCodeAt(0)<299) {
                l++;
            } else {
                l+=3;
            }
        }
        return l;
    }

    var count = 180;

    function phoneSubmit(){
        if($('#phone').val()=='' || $("#phone").val() == "请输入手机号码"){
            $('#dialog').dialog({
                modal:true, //蒙层（弹出会影响页面大小）
                title:'系统提示',
                buttons:{"确定":function(){$(this).dialog("close");}},
                close: function() {
                }
            });
            $("#msg").html("请输入手机号码");
            $("#phone").focus();
            return false;
        }else{
            $.ajax({
                type: "post",
                url: "/reg/apply_phone/",
                data: "phone="+$("#phone").val(),
                success: function(ret){
                    //$("#phone_code").html(ret.msg);
                    if(ret.info == 1){
                        phone_countdown();

                    }else{
                        $('#dialog').dialog({
                            modal:true, //蒙层（弹出会影响页面大小）
                            title:'系统提示',
                            buttons:{"确定":function(){$(this).dialog("close");}},
                            close: function() {
                            }
                        });
                        $("#msg").html(ret.msg);
                    }


                },
                dataType: "json"
            });
        }

    }


    function phone_countdown(){
        var count = 60;
        var countdown = setInterval(CountDown, 1000);

        function CountDown() {
            $("#phone_code").html('<font style="color:#ff6600;">'+count+"</font>秒后重试");
            if (count == 0) {
                $("#phone_code").html('获取验证码');
                clearInterval(countdown);
            }
            count--;
        }

    }

</script>



